import { createRouter, createWebHistory } from 'vue-router'

/* 路由匹配 */
const routes = [
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('@/views/layout/index.vue'),
    children: [
      {
        path: '',
        component: () => import('@/views/Home/index.vue')
      },
      {
        path: '/category/:id',
        name: 'category',
        component: () => import('@/views/Category/index.vue')
      },
      {
        path: '/category/sub/:id',
        component: () => import('@/views/SubCategory/index.vue')
      },
      {
        path: '/detail/:id',
        name:"detail",
        component: () => import('@/views/Detail/index.vue')
      },
      {
        path:'/cartlist',
        name:'cartlist',
        component:()=> import('@/views/CartList/index.vue')
      },
      {
        path:'/checkout',
        name:'checkout',
        component:()=>import('@/views/checkOut/index.vue')
      },
      {
        path:'/pay',
        name:'pay',
        component:()=>import('@/views/Pay/index.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue')
  }
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
  scrollBehavior(){ /* 路由切换自动回到顶部    */
    return{
      top:0
    }
  }
})

export default router
